package cn.jbit.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.core.convert.converter.Converter;
/**
 *自定义类型转换器
 */
public class StringToDateConverter implements Converter<String, Date>{
	//定义时间格式
	private String datePattern;
	public StringToDateConverter(String datePattern){
		this.datePattern=datePattern;
	}
	
	/**
	 * 将字符符时间转换Date
	 */
	@Override
	public Date convert(String str) {
		Date date=null;
		try {
			date=new SimpleDateFormat(this.datePattern).parse(str);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}

}
